package com.fm.demo.joke

import androidx.fragment.app.Fragment
import com.fm.common.base.BaseBFragment
import com.fm.common.base.BaseFragmentAdapter
import com.fm.demo.R
import com.fm.demo.databinding.FragmentJokeMainBinding
import com.google.android.material.tabs.TabLayoutMediator

/**
 * @CreateData:     2019/11/26 15:48
 * @E-Mail:         709674174@qq.com
 * @Author:         lyy
 * @Description:    笑话，主界面
 */
class JokeMainFragment : BaseBFragment<FragmentJokeMainBinding>() {
    private val mFragments = ArrayList<Fragment>()

    override fun initView() {
        mFragments.add(JokeHomeFragment.newInstance(JokeHomeFragment.TYPE_ALL))
        mFragments.add(JokeHomeFragment.newInstance(JokeHomeFragment.TYPE_TEXT))
        mFragments.add(JokeHomeFragment.newInstance(JokeHomeFragment.TYPE_VIDEO))
        mFragments.add(JokeHomeFragment.newInstance(JokeHomeFragment.TYPE_IMAGE))
        mFragments.add(JokeHomeFragment.newInstance(JokeHomeFragment.TYPE_GIF))

        val mTitles = arrayOf(
            R.string.joke_all_fragment_title,
            R.string.joke_text_fragment_title,
            R.string.joke_video_fragment_title,
            R.string.joke_image_fragment_title,
            R.string.joke_gif_fragment_title
        )
        binding?.let { bind ->
            bind.fragmentMainVp.adapter = BaseFragmentAdapter(mContext as JokeMainActivity, mFragments)
            TabLayoutMediator(
                bind.fragmentMainTl, bind.fragmentMainVp
            ) { tab, position ->
                tab.text = getString(mTitles[position])
                tab.tag = position
            }.attach()
        }
    }

}